import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    props: router => ({ query: router.query })
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: false,
    children: [
      {
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-house', affix: true }
    }
  ]
  },

  // 404 page must be placed at the end !!! 这里本来到404页面，现在到首页
  { path: '*', redirect: '/', hidden: true }
]

export const asyncRoutes = [
  {
    path: '/dataStatistics',
    component: Layout,
    redirect: '/dataStatistics/index',
    meta: {
      roles: [0] // you can set roles in root nav
       //if do not set roles, means: this page does not require permission
     },
    children: [
      {
      path: 'index',
      name: 'DataStatistics',
      component: () => import('@/views/dataStatistics/index'),
      meta: { title: '数据统计', icon: 'el-icon-coin' }
    }
  ]
  },
  {
    path: '/retrievalNumber',
    component: Layout,
    redirect: '/retrievalNumber/index',
    meta: {
     roles: [0,1] // you can set roles in root nav
      //if do not set roles, means: this page does not require permission
    },
    children: [
      {
        path: 'index',
        name: 'RetrievalNumber',
        component: () => import('@/views/retrievalNumber/index'),
        meta: { title: '建筑企业', icon: 'el-icon-connection' },
        hidden: false
      },
      {
        path: 'info',
        name: 'retrievalInfo',
        component: () => import('@/views/retrievalNumber/info/index'),
        meta: { title: '企业详情', icon: 'el-icon-document', activeMenu: '/retrievalNumber/index' },
        hidden: true,
        props: router => ({ query: router.query })
      }
    ]
  },
  {
    path: '/talentPerson',
    component: Layout,
    redirect: '/talentPerson/index',
    meta: {
    roles: [0,2] // you can set roles in root nav
      //if do not set roles, means: this page does not require permission
    },
    children: [
      {
        path: 'index',
        name: 'TalentPerson',
        component: () => import('@/views/talentPerson/index'),
        meta: { title: '从业人员', icon: 'el-icon-connection' },
        hidden: false
      },
      {
        path: 'info',
        name: 'talentInfo',
        component: () => import('@/views/talentPerson/info/index'),
        meta: { title: '人才详情', icon: 'el-icon-document', activeMenu: '/talentPerson/index' },
        hidden: true
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    // redirect: '/project/index',
    name: '工程项目',
    meta: {
      title: '工程项目', // 设置该路由在侧边栏和面包屑中展示的名字
      icon: 'el-icon-connection',
      roles: [0,3] // you can set roles in root nav
      //if do not set roles, means: this page does not require permission
    },
    children: [
      {
        path: 'index',
        name: 'Project',
        component: () => import('@/views/project/index'),
        meta: { title: '四库', icon: 'el-icon-connection', activeMenu: '/project/index' },
        hidden: false
      },
      {
        path: 'water',
        name: 'Water',
        component: () => import('@/views/project/water'),
        meta: { title: '水利', icon: 'el-icon-connection', activeMenu: '/project/water' },
        hidden: false
      },
      {
        path: 'info',
        name: 'projectInfo',
        component: () => import('@/views/project/info/index'),
        meta: { title: '四库详情', icon: 'el-icon-document', activeMenu: '/project/index' },
        hidden: true
      },
      {
        path: 'waterInfo',
        name: 'waterInfo',
        component: () => import('@/views/project/info/water'),
        meta: { title: '水利详情', icon: 'el-icon-document', activeMenu: '/project/water' },
        hidden: true
      }
    ]
  },
  {
    path: '/report',
    component: Layout,
    // redirect: '/report/EnterpriseReport',
    name: '数据报表', // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
    meta: {
      title: '数据报表', // 设置该路由在侧边栏和面包屑中展示的名字
      icon: 'el-icon-pie-chart',
      roles: [0]
    },
    hidden: false,
    children: [
      {
        path: 'EnterpriseReport',
        name: 'EnterpriseReport',
        component: () => import('@/views/report/EnterpriseReport'),
        meta: { title: '建筑企业报表', icon: 'el-icon-pie-chart' }
      },
      {
        path: 'PersonnelReport',
        name: 'PersonnelReport',
        component: () => import('@/views/report/PersonnelReport'),
        meta: { title: '从业人员报表', icon: 'el-icon-pie-chart' }
      },
      {
        path: 'DataVolumeStatistics',
        name: 'DataVolumeStatistics',
        component: () => import('@/views/report/DataVolumeStatistics'),
        meta: { title: '数据量统计', icon: 'el-icon-pie-chart' }
      },
      {
        path: 'PersonnelCheck',
        name: 'PersonnelCheck',
        component: () => import('@/views/report/PersonnelCheck'),
        meta: { title: '用户统计', icon: 'el-icon-pie-chart' }
      }
    ]
  },
  {
    path: '/userManagement',
    component: Layout,
    redirect: '/userManagement/index',
    name: '用户管理',
    meta: {
      title: '用户管理',
      icon: 'el-icon-user',
      roles: [0]
    },
    children: [
      {
      path: 'index',
      name: 'UserManagement',
      component: () => import('@/views/userManagement/index'),
      meta: { title: '用户列表', icon: 'el-icon-user'},
      hidden: false
    },
    {
      path: 'loginLogs',
      name: 'LoginLogs',
      component: () => import('@/views/userManagement/loginLogs'),
      meta: { title: '登录日志', icon: 'el-icon-notebook-2'},
      hidden: false
    },
    {
      path: 'visitLogs',
      name: 'VisitLogs',
      component: () => import('@/views/userManagement/visitLogs'),
      meta: { title: '访问日志', icon: 'el-icon-notebook-2'},
      hidden: false
    },
    {
      path: 'unLockLogs',
      name: 'UnLockLogs',
      component: () => import('@/views/userManagement/unLockLogs'),
      meta: { title: '解锁日志', icon: 'el-icon-notebook-2'},
      hidden: false
    },
    {
      path: 'checkLogs',
      name: 'CheckLogs',
      component: () => import('@/views/userManagement/checkLogs'),
      meta: { title: '企业从业人员查看日志', icon: 'el-icon-notebook-2'},
      hidden: false
    },
    {
      path: 'contactLogs',
      name: 'ContactLogs',
      component: () => import('@/views/userManagement/contactLogs'),
      meta: { title: '企业联系人查看日志', icon: 'el-icon-notebook-2'},
      hidden: false
    },
  ]
  },
  {
    path: '/systemConfiguration',
    component: Layout,
    redirect: '/systemConfiguration/index',
    meta: {
      roles: [0]
    },
    children: [{
      path: 'index',
      name: 'SystemConfiguration',
      component: () => import('@/views/systemConfiguration/index'),
      meta: { title: '系统配置', icon: 'el-icon-setting' },
      hidden: false
    }]
  },
  {
    path: '/adminPerson',
    component: Layout,
    redirect: '/adminPerson/index',
    meta: {
      roles: [0]
    },
    children: [{
      path: 'index',
      name: 'AdminPerson',
      component: () => import('@/views/adminPerson/index'),
      meta: { title: '人才管理', icon: 'el-icon-postcard' },
      hidden: false
    }]
  }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
